<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page isELIgnored="false" %>
<%@ include file="/WEB-INF/views/common/includes.jsp" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<link rel="stylesheet" href="<c:url value='/static/flexigrid/css/flexigrid.css'/>" type="text/css" media="screen, projection"/>
<script type="text/javascript" src="<c:url value='/static/flexigrid/js/flexigrid.js'/>"></script>
<script type="text/javascript" src="<c:url value='/static/js/jquery.switchify-1.0.js'/>"></script>

<script type="text/javascript">
$(function() {
    $("#flex1").flexigrid({
            url: '<c:url value="/es/admin/organization/list2/table"/>',
            dataType: 'json',
            colModel : [
                    {display: 'ID', name : 'id', width : 40, sortable : true, align: 'left'},
                    {display: 'CIF', name : 'cif', width : 150, sortable : true, align: 'left'},
                    {display: 'Name', name : 'name', width : 150, sortable : true, align: 'left'},
                    {display: 'Domain', name : 'domain', width : 150, sortable : true, align: 'left'},
                   
            ],
            buttons : [
                    {name: 'Edit', bclass: 'edit', onpress : doCommand},
                    {name: 'Delete', bclass: 'delete', onpress : doCommand},
                    {name: 'Add Applications', bclass: 'add', onpress : doCommand},
                    {separator: true}
            ],
            searchitems : [
					{display: 'ID', name : 'id'},       
					{display: 'CIF', name : 'cif'},       
                    {display: 'Name', name : 'name'},
                    
            ],
            sortname: "id",
            sortorder: "asc",
            usepager: true,
            title: "Organizations",
            useRp: true,
            rp: 5,
            showTableToggleBtn: false,
            resizable: false,
            width: 600,
            height: 370,
            singleSelect: true
    });
});

function doCommand(command, grid) {
	var action = "";
	$('.trSelected', grid).each(function() {
		var id = $(this).attr('id');
		id = id.substring(id.lastIndexOf('row')+3);
			
		if(command == "Add Applications") {
			action = '<c:url value="/es/admin/organization/"/>' + id + '/applications';
		} else if(command == "Edit") {
			action = "";
		} else if(command == "Delete") {
			action = "";
		}
	   	window.location = action;
	});
}
</script>

<div class="span-16 last table">		
	<table id="flex1">
		
	</table>
</div>